package com.fsoft.manager.file.service.impl;

import java.math.BigDecimal;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fsoft.core.Global;
import com.fsoft.core.common.base.service.impl.BaseServiceImpl;
import com.fsoft.core.common.exceptions.RRException;
import com.fsoft.core.utils.OgnlUtils;
import com.fsoft.manager.file.entity.SmsBsFileVo;
import com.fsoft.manager.file.mapper.SmsBsFileMapper;
import com.fsoft.manager.file.service.SmsBsFileService;

@Service("SmsBsFileServiceImpl")
@Transactional
public class SmsBsFileServiceImpl extends BaseServiceImpl<SmsBsFileVo> implements SmsBsFileService {
	@Autowired
	private SmsBsFileMapper mapper;

	@Override
	public int modify(SmsBsFileVo entity) throws Exception {
		if (StringUtils.isBlank(entity.getId()))
			throw new RRException("ID标识不允许为空");
		SmsBsFileVo dbEnt = getEntity(entity.getId());
		if (dbEnt == null)
			throw new Exception("记录为空");
		return super.modify(entity);
	}

	@Override
	public int save(SmsBsFileVo param) throws Exception {
		if (StringUtils.isBlank(param.getFilePath()))
			throw new Exception("保存路径标识无法识别！");
		if (StringUtils.isBlank(param.getBsId()))
			throw new Exception("bsId标识无法识别！");
		if (OgnlUtils.isEmpty(param.getFileType()))
			param.setFileType(Global.STATUS_YES);
		if (OgnlUtils.isEmpty(param.getSortNo())) {
			BigDecimal sortNo = mapper.selectMaxSort(param.getBsId());
			param.setSortNo(sortNo.add(BigDecimal.ONE)); // 最大排序号递增1
		}
		return super.save(param);
	}

}
